package com.gin.no_gay_alliance.fragment.main;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.gin.no_gay_alliance.databinding.FragmentMainDailyBinding;
import com.gin.no_gay_alliance.fragment.base.BaseBindingFragment;
import com.gin.no_gay_alliance.fragment.daily.DynamicsFragment;
import com.gin.no_gay_alliance.fragment.daily.FollowUserFragment;
import com.gin.no_gay_alliance.fragment.daily.MissionFragment;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

/**
 * 日常
 *
 * @author : ginstone
 * @version : v1.0.0
 * @since : 2023/9/13 09:47
 **/
public class MainDailyFragment extends BaseBindingFragment<FragmentMainDailyBinding> {

    private TabLayoutMediator tabLayoutMediator;

    /**
     * onCreateView 的后续操作
     */
    @Override
    protected void onCreateView() {
        b.vp2.setAdapter(new FragmentStateAdapter(this) {
            @NonNull
            @Override
            public Fragment createFragment(int position) {
                switch (position) {
                    case 0:
                        return new MissionFragment();
                    case 1:
                        return new DynamicsFragment();
                    case 2:
                        return new FollowUserFragment();
                    default:
                        throw new IllegalStateException("Unexpected value: " + position);
                }
            }

            @Override
            public int getItemCount() {
                return 3;
            }
        });

        tabLayoutMediator = attachTabLayout(tabLayoutMediator, b.tabLayout, b.vp2);
    }

    /**
     * 配置 TabLayout
     *
     * @param tab      标签
     * @param position 位置
     */
    @Override
    public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
        switch (position) {
            case 0:
                tab.setText("任务");
                break;
            case 1:
                tab.setText("关注动态");
                break;
            case 2:
                tab.setText("关注列表");
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + position);
        }
    }
}
